package org.owasp.oss.client.command;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract class CommandBase implements CommandInterface {
	
	protected static final String OS_HOST = "http://localhost:8080/";
	
	protected void writeFile(String fileName, byte[] content) {
		try {
			OutputStream stream = new FileOutputStream(fileName);
			stream.write(content);
			stream.flush();
			stream.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	protected byte[] readFile(String fileName) {
		try {
			InputStream fis = new FileInputStream(fileName);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();			
			int b;
			while ((b = fis.read()) != -1)
				baos.write(b);
			return baos.toByteArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
